package com.yh.patterns.prototype.test1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @Auther:云尚学Java
 */
public class Client {
    public static void main(String[] args) throws Exception {
        //创建原型对象
        Citation citation=new Citation();
        //创建学生对象云尚
        Student student=new Student();
        student.setName("云尚");
        citation.setStudent(student);

        /**
         * 深克隆
         */

        //创建对象输出流对象
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("C:\\Users\\admin\\Desktop\\java学习笔记\\设计模式\\prototype.txt"));
        //写对象
        oos.writeObject(citation);
        //释放资源
        oos.close();

        //读取对象
        //创建对象输入流对象
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("C:\\Users\\admin\\Desktop\\java学习笔记\\设计模式\\prototype.txt"));
        //读取对象
        Citation citation1 = (Citation) ois.readObject();
        //释放资源
        ois.close();

        Student student1=citation1.getStudent();
        student1.setName("四维");

        citation.show();
        citation1.show();
    }
}
